import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { TreeTableNode } from '@iux/live';
import { TreetableService } from '../tree-table.service';

@Component({
  selector: 'app-virtual-scroll-without-subnode',
  templateUrl: './virtual-scroll-without-subnode.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class VirtualScrollWithoutSubnodeComponent implements OnInit {
  data: TreeTableNode[];

  constructor(private treetableService: TreetableService, private cdr: ChangeDetectorRef) {}

  ngOnInit() {
    this.initAsyncData();
  }

  initAsyncData() {
    this.treetableService.getUsers().subscribe((res: TreeTableNode[]) => {
      this.data = res;
      this.cdr.markForCheck();
    });
  }

  trackByIndex(index, item) {
    return index;
  }
}
